03. Instructions
Project Rubric
Your project will be evaluated by a Udacity code reviewer according to the Classic Arcade Game Clone project rubric. Please review for detailed project requirements.
Overview: Game Functionality
Your implementation must at minimum follow the basic functionality, but you can add additional optional functionality to your game, if you wish.
Basic Functionality
In this game you have a Player and Enemies (bugs). The goal of the player is to reach the water, without colliding into any one of the enemies.
- The player can move left, right, up and down
- The enemies move at varying speeds on the paved block portion of the game board
- Once a the player collides with an enemy, the game is reset and the player moves back to the starting square
- Once the player reaches the water (i.e., the top of the game board), the game is won
Check out a quick video demo of the game in action below!
ArcadeGameDemo
Additional Functionality (Optional)
In addition to the basic functionality, you can add more cool functionality to your game. For example, here are some additional features that you can add:
- Player selection: allow the user to select the image for the player character before starting the game. You can use the different character images provided in the images folder (we’ll get to that below)
- Score: you can implement a score for the game. For example, the score can increase each time the player reaches the water, and it can be reset to 0 when collision occurs (or it can be reduced)
- Collectibles: you can add gems to the game, allowing the player to collect them to make the game more interesting
- Anything else you like!
First, Get the Starter Code
You won’t have to build the game from scratch. We have provided the art assets and game engine for you. You can download or clone them from our repository.
The repository contains css
, images
, and js
folders, as well as an index.html
and a README.md
file.
- The
css
folder contains astyle.css
file which you do not need to edit - The
images
folder contains the png image files, which are used when displaying the game. The images for the player and enemy character are going to be loaded from this folder. - The
js
folder also contains the app engine needed to run the game and aresources.js
file. You do not need to edit these files. - Opening
index.html
should load the game - The
README.md
file should contain instructions on how to load and play the game (you will need to add those instructions).
Once you have downloaded the files we have provided, you will have to edit app.js
to build the game.
Object-Oriented JavaScript
Great! You have the starter code. But before moving on, make sure you are comfortable with the content from Object-Oriented JavaScript. Ask yourself:
- What is an object?
- How is an object different from a primitive in JavaScript (e.g., can a primitive have methods?)
- What are some ways to create or instantiate a new object?
- How do you modify properties, or add/remove properties from an object?
- What is a constructor function (or class)?
- What is
this
? What does it refer to and how is it used in different contexts (i.e., in a constructor function, a method, etc.)? - How do you add a property or method to a constructor's prototype?
- What is prototypal inheritance and how is it implemented?
Development Strategy
Inside the app.js
file, you will need to implement the Player
and the Enemy
classes, using Object-Oriented JavaScript. Be sure to review all code comments written in app.js
. Part of the code for the Enemy
is provided to you, and you will need to complete the following:
- The
Enemy
function, which initiates theEnemy
by:- Loading the image by setting
this.sprite
to the appropriate image in the image folder (already provided) - Setting the
Enemy
initial location (you need to implement) - Setting the
Enemy
speed (you need to implement)
- Loading the image by setting
- The
update
method for theEnemy
:- Updates the
Enemy
location (you need to implement) - Handles collision with the
Player
(you need to implement)
- Updates the
You can add your own Enemy
methods as needed. You will also need to implement the Player
class, and you can use the Enemy
class as an example on how to get started. At minimum you should implement the following:
- The
Player
function, which initiates thePlayer
by:- Loading the image by setting
this.sprite
to the appropriate image in theimage
folder (use the code from theEnemy
function as an example on how to do that) - Setting the
Player
initial location
- Loading the image by setting
- The
update
method for thePlayer
(can be similar to the one for theEnemy
) - The
render
method for the Player (use the code from the render method for theEnemy
) - The
handleInput
method, which should receive user input,allowedKeys
(the key which was pressed) and move the player according to that input. In particular:- Left key should move the player to the left, right key to the right, up should move the player up and down should move the player down
- Recall that the player cannot move off screen (so you will need to check for that and handle appropriately)
- If the player reaches the water the game should be reset by moving the player back to the initial location (you can write a separate reset
Player
method to handle that)
You can add your own Player
methods as needed as well. Once you have completed implementing the Player
and Enemy
, you should instantiate them by:
- Creating a new
Player
object - Creating several new
Enemy
objects and placing them in an array calledallEnemies
Beyond that, feel free to add additional functionality to the game. You can add more code to the app.js
file and to the Enemy
and Player
classes to accomplish that. Feel free to use implement any ideas from the section titled Additional Functionality (Optional) above.
HTML5 Canvas Info
The starting code for the Classic Arcade Game Clone project handles most of the drawing for you. The <canvas>
element has already been created and the two-dimensional drawing context for the canvas element is available as the ctx
object in the app.js
file.
Drawing an Image
In the app.js
file, you can see in the Enemy class. This class has a render()
method that uses the ctx.drawImage()
method. This method takes three parameters: an image, an x-coordinate, and a y-coordinate:
ctx.drawImage(Resources.get(this.sprite), this.x, this.y);
Available Images
In this example, the game engine has a Resources
object that caches all of the images needed for the game so you don’t have to wait for them to load during gameplay. The images available to use are listed in engine.js
:
Resources.load([
'images/stone-block.png',
'images/water-block.png',
'images/grass-block.png',
'images/enemy-bug.png',
'images/char-boy.png'
]);
There are many other images available with the starter code. If you want to use them in your game, all you need to do is include them in the array passed to the Resources.load()
method in engine.js
near the bottom of the file:
Resources.load([
'images/stone-block.png',
'images/water-block.png',
'images/grass-block.png',
'images/enemy-bug.png',
'images/char-boy.png',
'images/char-pink-girl.png'
]);
Expanding on the Existing Capabilities?
It’s unlikely that you’ll need any additional methods of the ctx
object for the project. However, if you decide to add additional features to your game, you might want to incorporate some of these methods. If you do, the ctx
object is a CanvasRenderingContext2D
object. This documentation provides all of the methods that are available to that object.
Still Not Sure How to Begin?
Let's recap how you can approach this project:
- If you need a refresher on Object-Oriented JavaScript, review our course and OOJS Notes
- Above are a few notes on HTML5 Canvas, but if you'd like a more detailed explanation as to how the game engine works, see our HTML5 Canvas course
- Review how the game functions. How is it played? What does the user get to control? What are the winning and losing conditions?
- Download the art assets and provided game engine (starter code)
- Review all code and comments provided in the starter code's
app.js
file - Identify the various classes you will need to write
- Identify and code the properties that each class must have to accomplish its tasks
- Write the functions that provide functionality to each of your class instances
- Review the project rubric to make sure your project is up to spec. For example, make sure the functions you write are object-oriented; either class functions (like
Player
andEnemy
) from ES6 or class prototype functions such asEnemy.prototype.checkCollisions
, and that the keywordthis
is used appropriately within your class and class prototype functions. Also, be sure that theREADME.md
file is updated with your instructions on both how to run and play your arcade game - You are welcome to use
ES6
to build your classes
For further research, check out these additional resources in Knowledge, curated by students. Feel free to review some external resources below: